package utils;

import java.awt.Point;

public class GameMaths {

	public static float getDistance(Point a, Point b) {
		float dist = 0.0f;
		int along = Math.abs(a.x - b.x);
		int blong = Math.abs(a.y - b.y);

		dist = (float) Math.sqrt(Math.pow(along - blong, 2));

		return dist;
	}

	public static double getAngle(Point a, Point b) {

		double difx = b.x - a.x;
		double dify = b.y - a.y;
		double hipotenusa = Math.sqrt((difx * difx) + (dify * dify));

		return Math.acos(dify / hipotenusa);
	}

	public static float distance(float x, float y, float x2, float y2) {
		float dx = Math.abs(x - x2);
		float dy = Math.abs(y - y2);
		float ret = (float) Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
		return ret;
	}

	public static float angle(float x, float y, float x2, float y2) {
		float dx = (x - x2) * 100;
		float dy = (y - y2) * 100;

		double angle = 0.0d;

		if (dx == 0.0) {
			if (dy == 0.0)
				angle = 0.0;
			else if (dy > 0.0)
				angle = Math.PI / 2.0;
			else
				angle = (Math.PI * 3.0) / 2.0;
		} else if (dy == 0.0) {
			if (dx > 0.0)
				angle = 0.0;
			else
				angle = Math.PI;
		} else {
			if (dx < 0.0)
				angle = Math.atan(dy / dx) + Math.PI / 2;
			else if (dy < 0.0)
				angle = Math.atan(dy / dx) + (Math.PI);
			else
				angle = Math.atan(dy / dx);
		}
		return (float) ((angle * 180) / Math.PI);
	}
}
